﻿using System;
using System.Collections.Generic;
using System.Text;

namespace XProject.Commons.BaseUtil
{
    public class StringUtils
    {
        /// <summary>
        /// 把Http URL格式的字符串拿掉最后一个"/", 转化成 Class Name 格式
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string UrlToClassName(string url)
        {
            return url.Substring(0, url.LastIndexOf("/")).Replace("/", ".").Replace(" ", "");
        }

        /// <summary>
        /// 取Http URL字符串最后一个"/"作为方法名字.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string UrlToMethodName(string url)
        {
            int lastIndex = url.LastIndexOf(".");
            if (lastIndex == -1)
            {
                return url.Substring(url.LastIndexOf("/") + 1).Replace(" ", "");
            }
            else 
            {
                int startIndex = url.LastIndexOf("/") + 1;
                return url.Substring(startIndex, lastIndex - startIndex).Replace(" ", "");
            }
           
        }
    }
}
